{extend name="common:frm_base" /}
{block name="content"}
<style>
    .layui-input-inline{width:350px!important;}
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">服务队管理</div>
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" action="{:url('site_team/handle')}" lay-filter="component-form-group">
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:120px;">服务队名称</label>
                    <div class="layui-input-inline">
                        <input type="text" value="{$info.name|default=''}" name="name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <input type="hidden" name="type_id" value="1">
<!--                <div class="layui-form-item">-->
<!--                    <label class="layui-form-label" style="width:120px;">类型</label>-->
<!--                    <div class="layui-input-inline">-->
<!--                        <select name="type_id" lay-filter="aihao">-->
<!--                            <option value="0" {if $info.sid}selected{/if}>站点</option>-->
<!--                            <option value="1" {if $info.oid}selected{/if}>服务队</option>-->
<!--                        </select>-->
<!--                    </div>-->
<!--                </div>-->
<!--                <div class="layui-form-item {if !$info.sid}layui-hide{/if}" id="site">-->
<!--                    <label class="layui-form-label" style="width:120px;">归属站点</label>-->
<!--                    <div class="layui-input-inline">-->
<!--                        <select name="sid" lay-verify="required">-->
<!--                            <option value="0">请选择站点</option>-->
<!--                            {volist name="site" id="val"}-->
<!--                            <option {if $info.sid==$val.id}selected{/if} value="{$val.id}">{$val.name}</option>-->
<!--                            {/volist}-->
<!--                        </select>-->
<!--                    </div>-->
<!--                </div>-->
                <div class="layui-form-item" id="site_team">
                    <label class="layui-form-label" style="width:120px;">归属服务队</label>
                    <div class="layui-input-inline">
                        <div id="oid_id" class="xm-select-demo"></div>
                        <input type="hidden" name="oid" id="oid" value="{$info.oid|default=0}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:120px;">负责人</label>
                    <div class="layui-input-inline">
                        <input type="text" value="{$info.realname|default=''}" name="realname" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:120px;">手机号码</label>
                    <div class="layui-input-inline">
                        <input type="text" value="{$info.mobile|default=''}" name="mobile"  placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:120px;">身份证号</label>
                    <div class="layui-input-inline">
                        <input type="text" value="{$info.id_card|default=''}" name="id_card"  placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:120px;">所属镇街</label>
                    <div class="layui-input-inline">
                        <select name="street_id" lay-search="">
                            <option value="0">请选择镇街</option>
                            {volist name="street" id="val"}
                            <option {if $info.street_id==$val.id}selected{/if} value="{$val.id}">{$val.name}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">存折管理会员</label>
                    <div class="layui-input-block">
                        <div id="pass_id" class="xm-select-demo1"></div>
                        <input type="hidden" name="pass_id" id="pass">
                    </div>
                </div>
                <script>
                    $(function(){
                        $.post("{:url('site/get_user',array('id'=>$id,'type'=>3))}",{},function(res){
                            var list = res.list;
                            var demo2 = xmSelect.render({
                                el: '#pass_id',
                                filterable: true,
                                paging: true,
                                data:list,
                                on:function(e){
                                    var arr = demo2.getValue();
                                    var str = '';
                                    for(var item in arr){
                                        str+=','+arr[item].value;
                                    }
                                    if(e.isAdd){
                                        str+=','+e.change[0].value;
                                    }
                                    str = str.substr(1);
                                    $('#pass').val(str);
                                }
                            });
                        },'json');
                    })
                </script>
                {if !$_SESSION['xm_travel']['admin_info']['oid']}
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:120px;">前端管理用户</label>
                    <div class="layui-input-inline">
                        <select name="user_id" lay-search="">
                            <option value="0">请选择会员</option>
                            {volist name="list" id="val"}
                            <option {if $info.user_id==$val.id}selected{/if} value="{$val.id}">{$val.nick_name}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:120px;">状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="status" value="0" {if $info['status']==0}checked{/if} title="审核中">
                        <input type="radio" name="status" value="1" {if $info['status']==1}checked{/if} title="审核通过">
                        <input type="radio" name="status" value="2" {if $info['status']==2}checked{/if} title="审核不通过">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:120px;">是否发布</label>
                    <div class="layui-input-block">
                        <input type="radio" name="is_add" value="0" {if $info['is_add']==0}checked{/if} title="否">
                        <input type="radio" name="is_add" value="1" {if $info['is_add']==1}checked{/if} title="是">
                    </div>
                </div>
                {else /}
                <input type="hidden" name="user_id" value="{$info.user_id}">
                {/if}
                {:token()}
                <input type="hidden" value="{$act}" name="act" />
                <input type="hidden" value="{$info['id']|default=''}" name="id" />
                <div class="layui-form-item layui-hide">
                    <input type="button" lay-submit lay-filter="LAY-user-front-submit" id="LAY-user-front-submit" value="确认">
                </div>
                <!--<div class="layui-form-item layui-layout-admin">-->
                <!--<div class="layui-input-block">-->
                <!--<div class="layui-footer" style="left: 0;">-->
                <!--<button class="layui-btn" lay-submit="" lay-filter="component-form-demo1">立即提交</button>-->
                <!--<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
                <!--</div>-->
                <!--</div>-->
                <!--</div>-->
            </form>
        </div>
    </div>
</div>
<script src="/static/admin/xm-select.js"></script>
<script>
    $(function(){
        $.post("{:url('site_team/get_site_team',array('oid'=>$info['oid']))}", {}, function (res) {
            console.info(JSON.stringify(res));
            var list = res.list;
            var demo1 = xmSelect.render({
                el: '#oid_id',
                filterable: true,
                paging: true,
                max: 1,
                data: list,
                on: function (e) {
                    var arr = demo1.getValue();
                    var str = '';
                    for (var item in arr) {
                        str += ',' + arr[item].value;
                    }
                    if (e.isAdd) {
                        str += ',' + e.change[0].value;
                    }
                    str = str.substr(1);
                    $('#oid').val(str);
                }
            });
        }, 'json');
    })
</script>
<script>
    layui.config({
        base: '__LAYUIADMIN__/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate', 'upload'], function(){
        var $ = layui.$
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,form = layui.form
            ,upload = layui.upload;

        form.render(null, 'component-form-group');

        laydate.render({
            elem: '#begin_time'
            ,type: 'date'
        });


        upload.render({
            elem: '#driving_license_btn'
            ,url: "{:url('common/upload_img')}"
            ,data: {src_name:'bus'}
            ,accept: 'images'
            ,acceptMime: 'image/*,image/gif'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#driving_license_img').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    $('#driving_license_img').attr('src', " ");
                    layer.msg('上传失败');
                } else{
                    $("input[name='driving_license']").val(res.data);
                    layer.msg('上传成功');
                }
                //上传成功
            }
            // ,error: function(){
            //     //演示失败状态，并实现重传
            //     var demoText = $('#test-upload-demoText');
            //     demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
            //     demoText.find('.demo-reload').on('click', function(){
            //         uploadInst.upload();
            //     });
            // }
        });

        $('#pic-list').viewer();

        $(".demo-reload").click(function () {
            $(this).parents('.layui-col-xs3').remove();//模拟前端删除按钮
            var img_urls = [];
            $(".layui-upload-img").each(function () {
                img_urls.push($(this).attr("data-src"));
            });
            $("#img_url").val(img_urls);
        });
        form.on('select(aihao)', function(data){
            if(data.value==1){
                $('#site').addClass('layui-hide');
                $('#site_team').removeClass('layui-hide');
            }else{
                $('#site_team').addClass('layui-hide');
                $('#site').removeClass('layui-hide');
            }
        });
        form.render(null, 'component-form-group');

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#bus_img_btn'
            , url: "{:url('common/upload_img')}"
            , data: {src_name:'bus'}
            , accept: 'images'
            , acceptMime: 'image/*,image/gif'
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                else {
                    $('#pic-list').append('<div class="layui-col-xs3">' +
                        '<img src="/uploads/' + res.data + '" class="layui-upload-img" data-src="' + res.data + '"">' +
                        '<p><button type="button" class="layui-btn layui-btn-xs demo-reload">删除</button></p></div>');

                    $(".demo-reload").click(function () {
                        $(this).parents('.layui-col-xs3').remove();//模拟前端删除按钮
                        var img_urls = [];
                        $(".layui-upload-img").each(function () {
                            img_urls.push($(this).attr("data-src"));
                        });
                        $("#img_url").val(img_urls);
                    });
                    var img_urls = [];
                    $(".layui-upload-img").each(function () {
                        img_urls.push($(this).attr("data-src"));
                    });
                    $("#img_url").val(img_urls);
                }
            }
            , error: function () {
            }
        });

    });

    function openImg(i) {
        layer.photos({
            photos: '#pic-list'
        });
    }
</script>
{/block}